export const formatVal = (num, unit, code, precision) => {
  if (!num) {
    return '';
  }
  let _num = num;
  if (unit === '%') {
    _num = (Number(_num) * 100).toFixed(1);
  }
  return Number(_num).toFixed(precision || 0);
};
export const formatToMMddByLevel = (str, level) => {
  const json = {};
  for (let i = 0, l = str.length; i < l; i++) {
    json[str[i]] = json[str[i]] + 1 || 1;
  }
  if (json['-'] > 1) {
    return str.substr(str.indexOf('-') + 1);
  } else {
    return str;
  }
};
export const formatToMMdd = (str, level) => {
  let newStr = str;
  const t = str.split('-');

  function formatNum(s) {
    if (s > 0 && s < 10 && s.indexOf('0') <= -1) {
      return `0${s}`;
    } else {
      return s;
    }
  }
  if (t.length === 3) {
    newStr = `${formatNum(t[0])}/${formatNum(t[1])}/${formatNum(t[2])}`;
  } else if (t.length === 2) {
    newStr = `${formatNum(t[0])}/${formatNum(t[1])}`;
  } else {}
  return newStr;
};
